//loginjs{
// 登录操作 获取数据,验证账号和密码

var locaUrl;
setTimeout("getLocation()");

function getLocation(){
	// 获取当前页面的完整 URL
	var currentUrl = window.location.href;
	// 提取网段部分
	var hostname = (new URL(currentUrl)).hostname;
	// 构建 Ajax 请求的 URL
	locaUrl = "http://" + hostname; //+ ":8080/recruitInfo";
}
function getData() {
	//判断用户是学生还是企业或管理员
	var who = document.getElementById('1').value;
	//获取用户输入的账号密码
	var inputAccount = document.getElementById(2).value;
	var inputPassword = document.getElementById(3).value;
	const data = {
		account:inputAccount,
		password:inputPassword
	};

	if (who == '学生用户') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/loginStu",data).then(result => {
			if (result.data.code == "1") {
				console.log(result.data.data);
				// document.cookie = result.data.data;
				sessionStorage.setItem("user",result.data.data);
				// sessionStorage.setItem("user",account);
				location = '/webapp/student.html';
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});
	}else if (who == '企业用户') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/loginCompany",data).then(result => {
			if (result.data.code == "1") {
				sessionStorage.setItem("user",result.data.data);
				location = '/webapp/company.html';
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});
	} else if (who == '管理员') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/loginAdmin",data).then(result => {
			if (result.data.code == "1") {
				sessionStorage.setItem("user",result.data.data);
				location = '/webapp/admin.html';
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});

	}


	
}
//注册操作
function registera() {
	//判断用户是学生还是企业或管理员
	var who = document.getElementById('1').value;
	//获取用户输入的账号密码
	var inputAccount = document.getElementById(5).value;
	var inputPassword = document.getElementById(6).value;

	const data = {
		account:inputAccount,
		password:inputPassword
	};

	if (who == '学生用户') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/registerStu",data).then(result => {
			console.log(result);
			if (result.data.code == "1") {
				alert("注册成功");
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});
	}else if (who == '企业用户') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/registerCompany",data).then(result => {
			if (result.data.code == "1") {
				alert("注册成功");
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});
	} else if (who == '管理员') {
		axios.withCredentials = true;
		axios.post(locaUrl+":8080/registerAdmin",data).then(result => {
			if (result.data.code == "1") {
				alert("注册成功");
			}else if(result.data.code == "0") {
				alert(result.data.msg);
			}
		});

	}

}

//切换提示框
function setPointName(user) {
	document.getElementById('1').value = user;
}

//切换登陆与注册的按钮
function changeButton(){
	document.getElementById('4').value = '注册';
	var module = document.getElementsByClassName("module");
	var module1 = document.getElementsByClassName("module1");
	module[0].classList.add("active");
	module1[0].classList.add("active");
}
function changeButton1(){
	document.getElementById('4').value = '登陆';
	var module = document.getElementsByClassName("module");
	var module1 = document.getElementsByClassName("module1");
	module[0].classList.remove("active");
	module1[0].classList.remove("active");
}

//密码的隐藏与显示
function changePassword(){
	var img = document.getElementById("眼睛");
	var password = document.getElementById("3");

	if(password.type == "text"){
		img.src = "img/闭眼.gif";
		password.type = "password";
		return;
	}else if(password.type == "password"){
		img.src = "img/睁眼.gif";
		password.type = "text";
		return;
	}
}



